Skip to content

Every open pull request has a record and one state, read by the merge gates and the new pull requests view - #985

Merged
nambok merged 9 commits into
mainfrom
pull-requests-view
Dec 6, 2026
Merged

nambok merged 9 commits into
mainfrom
pull-requests-view

Conversation

@nambok

@nambok nambok commented Dec 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A durable record for every open pull request in a team's connected repositories, people's as much as CoderHelm's, one shared function that decides each one's state and what it needs next from whom, and GET /api/prs for the dashboard's new Pull requests page.

  • The record (common::pr_record): one settings-table item per pull request, written from the webhooks already received (pull request, review, review and issue comments, check run, check suite, status, push) for every author, and kept honest by a bounded sync: one GraphQL search per organization at install and once an hour, under the shared GitHub budget. No expiry while the pull request is open.
  • One state per pull request (common::pr_needs::decide): a generalization of merge_standing. It returns exactly one of 19 states plus a visible unknown, a turn (a person, CoderHelm, the machines, done), and next{code, text, from, since, rule}. The sentence leads with the block, names who acts, and gives the rule's source (repo rule, CODEOWNERS, required check, team rule). For CoderHelm's own pull request it is the run's standing; typed hand-offs are shown as their own line, and CoderHelm's own limits stay CoderHelm's turn.
  • The gates and the list agree by construction: the run's pull request watch stores the standing pr_needs decides (run_standing), and the reviewer's auto-merge gate merges only what pr_needs says is ready.
  • History for the org overview, so the storage never has to be migrated (common::pr_history): every duration from ready for review, human review leaving out the author and every bot; each record's state and turn change log, people's reviews and review requests, and the checks turning red or green; links to CoderHelm's runs and review sessions, and revert and follow-up links; a history row for every merged or closed pull request, kept 400 days; and a nightly snapshot per org and repository with counts by stage and turn and the org's own percentiles (cycle p50/p85/p95, first human review p50/p85, each stage's p85), a repository under 30 merges in 90 days using its org's and an org under 8 weeks marked young. The overview's builder reads the shapes from docs/pull-requests/api_contract.md.
  • The API: GET /api/prs (filters for org, repo, turn, state, person, a query and the saved views; counts by turn, state, repo, org and view; limit/cursor/next) and GET /api/prs/detail (the path to merge, the wait ledger, the timeline with CoderHelm's runs). Under the "view" capability, scoped to the session's team.

Changes

  • services/common/src/pr_needs.rs (new): State, Turn, Rule, Facts, decide, run_standing, checklist.
  • services/common/src/pr_record.rs (new): the record, its pure event and sync appliers, the wait ledger, versioned writes, head and branch pointers, the sync's GraphQL search.
  • services/common/src/pr_view.rs (new): rows, stacked and plan links, the viewer's turn, staleness from the repository's own waits (the 75th percentile per state, never a fixed number of days), filters, counts, paging, ledger and timeline.
  • services/gateway/src/routes/prs.rs (new): the webhook writer and both endpoints; a 10 second cache keyed by read_key(installation_id, "prs#<team>").
  • github_webhook.rs: dispatch writes every pull request event's record before any handler's early return; installs and added repositories ask for a sync (PrRecordsSync). The "Only track our PRs" return stays for the run-only work below it.
  • services/worker/src/passes/pr_records.rs (new): the sync. worker/src/main.rs runs it on the sweep tick and on PrRecordsSync.
  • common/src/github_budget.rs: new caller sweep:dashboard_prs, 30 requests an hour; sweep:deploys gives up 30 so every sweep at its cap still fits the background share.
  • worker/src/passes/pr_watch.rs: stores pr_needs::run_standing. worker/src/passes/await_merge.rs: gate_facts, and the merge happens only when pr_needs says ready.
  • permissions.rs: prs::list_prs and prs::get_pr under "view". bm_teams_never_cross: the new cache.
  • Incident xw_every_open_pr_has_one_state (.rs and .md): every open pull request appears; one state each, with unknown shown and counted; the gate and the list agree over every combination of what the gate weighs, and the run's stored standing reads to the same state; no record of another team reaches a row.
  • services/common/src/pr_history.rs (new): History, Snapshot, Percentiles, stage_of lives in pr_needs; storage of history (400 days), revert and follow-up marks, and the snapshots. The gateway writes history when a pull request closes; the worker's sweep tick writes the snapshot once a day per team (bounded: 300 repositories, 25,000 history rows; no GitHub requests; no new process-wide cache).
  • docs/pull-requests.md (new): the record, the history and snapshot, the states, the API and the cost. docs/pull-requests/api_contract.md (new): the API and stored shapes.

Health signals stored for every pull request: separate author, reviewer and bot clocks (bots never reset the first two); drift as base commits touching the pull request's files; every check attempt, so failing then passing on one commit reads flaky; revert links (certain) and follow-up suspects with their reason; the review coverage state (human-approved, AI only, non-owner on owned paths, bypass or exempt, no review); bypass merges with the rule they went past and who merged (CoderHelm's own included); dependency and security category with severity, its clock from ready for review; and CoderHelm's last run outcome and stop reason. Every pull request means every author: the webhooks, the open sync and the 14-month history backfill keep people's, bots' and CoderHelm's alike, and nothing filters to CoderHelm's own pull requests.

Follow-ups, not in this change: CODEOWNERS versions and sensitive paths (non-owner coverage reads only GitHub's review decision today); policy events from the rule-suites API and the audit log; Dependabot and code-scanning alerts with KEV and EPSS, and the org's SLA table; default-branch CI episodes and a nightly flaky-check index; review comment counts; run cost and findings per pull request; the event feed; the digest and nudge settings.

Answers to the review on afe30c7, each fixed at its cause and tested:

  • The gate never waits on a review no rule requires, and is never stricter than GitHub.
    • Approvals are now weighed as two separate rules.
      • The repository's rule: GitHub's review decision is the authority. When GitHub reports no decision, nothing is required. APPROVED counts every approval GitHub counts, including an app's.
      • The team's own rule: only a person's approval meets it.
    • A requested reviewer whom no rule requires is named in the ready sentence ("also asked to review; no rule waits on it"), never as a hold.
    • Tests: pr_needs (optional asks, GitHub's decision), and incident xw: the agreement loop now also varies requested reviewers, the review decision and the branch's count over 4,096 combinations. Two direct gate cases (an optional ask with the team rule off, and GitHub's approval with no person's) both merge.
  • Events and the sync never undo each other.
    • apply_node never reopens a record an event closed.
    • When an event reached the record after the search was read (read_at, taken before the request), the page adds only what events never carry.
    • The reviews and review requests it reads replace the record's lists, so a dismissed review leaves it, and CoderHelm's verdict clears when GitHub lists none.
    • Checks and conversations read 100 per page with pageInfo. A cut list keeps the checks events reported, a required check that may be on a later page reads as unknown (never running), and a conversation rule with unread conversations reads as unknown.
    • Tests in pr_record cover each case.
  • History is never thinned.
    • Rows carry their source (events or search), and pr_history::put merges with the stored row: the events row wins, its empty fields are filled from the other, and revert and follow-up links come from both.
    • The backfill and the reconcile can no longer drop spans, runs, logs or CoderHelm's role.
    • Test: a_search_row_never_thins_a_row_written_from_events.
  • Review decision freshness.
    • The decision is worked out at each review and review request event, the way GitHub does it from the reviews and the branch's count, and it is stamped decision_at.
    • With code owners required it can't be told from events, so it keeps its last read and reads as stale.
    • Bypass and coverage use the decision, and GitHub's merge state, only when it is newer than the last review and request.
    • Tests: a_review_event_refreshes_the_review_decision and a_stale_review_decision_never_names_a_bypass.
  • Stack links join head and base in the same repository (head_repo, from the event or the search). A fork's branch never stacks the repository's pull requests. Test: a_forks_branch_never_stacks_the_repositorys_pull_requests.
  • The detail decides as the list does. pr_view::decided is the one input builder (linked records, facts, decision, row); rows and detail_of both read it. Test: the_detail_decides_a_stacked_pull_request_as_the_list_does.
  • One helper each.
    • pointer_sk(Pointer, repo, key) replaces head_sk and ref_sk.
    • pr_record::get_item and get_doc are the one read behind records, pointers, history rows and backfill progress (load, pointed, pr_history::load, load_backfill).
  • The suggestions.
    • The cache keeps how each source read, so a cache hit still names a reviewer read that failed.
    • A push reads only the pull requests a base-branch pointer names (PRRECBASE#), not every record of the repository.
  • The clippy failure noted on 3dd8045 was fixed on da7e4e7, which was green.

Where the code differed from the plan:

  • The contracts index holds no links between pull requests, so contract links come from the ## Compatibility heading of the description, the same place the index's own check writes them.
  • Required checks, code owners and conversation resolution come from the base branch's classic protection rule as GraphQL exposes it; rulesets aren't in the search result, so a ruleset-only requirement shows through GitHub's own review decision and merge state (branch rule).
  • The dashboard page is A Pull requests page: every open pull request, grouped by whose turn it is coderhelm#544. The selfhost/versions.json dashboardRef bump follows as its own change once that merges: scripts/bump-dashboard.sh pins a commit on the dashboard's main, which doesn't exist yet. Until then the hosted dashboard shows the page and an install's older dashboard simply doesn't link it.

Cost bounds:

  • Reading the list: no GitHub requests. One query of the team's records, one batched read of the runs they name, two reads of the reviewer's records; reused for 10 seconds.
  • Each webhook: one read and one conditional write of its record (retried from a fresh read when another write got there first).
  • The sync: at most 10 pages of 30 per organization, each a counted request asked of the budget first, at most 30 an hour per installation, only while the runs keep their share.

Verification

These checks were run on the branch after the review answers, merged with the org overview's read API (#988, merged into this branch) and with main (#986, #987).

  • cargo fmt --all --check and rustfmt --check --edition 2021 worker/src/passes/incidents/*.rs are clean.
  • cargo clippy -p common -p worker -p gateway --all-targets -- -D warnings is clean.
  • The full cargo test --no-fail-fast -p common -p worker -p gateway passed with no failures: common 3,392, gateway 1,370 and worker 2,998 tests, plus the integration tests.
  • 12 tests were written or extended for the review answers, and each ran and passed:
    • a_review_no_rule_requires_never_holds_the_merge
    • githubs_decision_counts_every_approval_that_counts_there
    • the_sync_never_reopens_a_closed_record_or_overwrites_newer_events
    • the_sync_is_the_authority_for_the_reviews_it_lists
    • a_list_cut_short_is_never_read_as_complete
    • a_review_event_refreshes_the_review_decision
    • one_pointer_helper_names_every_pointer
    • a_forks_branch_never_stacks_the_repositorys_pull_requests
    • the_detail_decides_a_stacked_pull_request_as_the_list_does
    • a_search_row_never_thins_a_row_written_from_events
    • a_stale_review_decision_never_names_a_bypass
    • incident xw's the_merge_gates_and_the_list_read_one_decision, now over 4,096 combinations plus two direct gate cases
  • The existing tests still pass: await_merge (including the_person_key_is_optional_when_the_repo_says_so), merge_standing, bm_teams_never_cross, the worker message contract and the GitHub budget caps.
  • brand_spelling.py, domain_examples.py and text_guard.py are clean on this description, the commit messages and the docs.

… gates and the new pull requests view

A durable record per open pull request in the team's connected repositories,
written from the webhooks already received for every author and kept honest by
a bounded GraphQL sync under the shared GitHub budget (sweep:dashboard_prs).
One function (pr_needs::decide) decides each pull request's state, its turn and
what it needs next from whom; the run's watch stores its standing and the
reviewer's auto-merge gate merges only what it calls ready. GET /api/prs and
GET /api/prs/detail serve the dashboard's pull requests page under the "view"
capability. Incident case xw holds it.
@nambok nambok added the ch-review CoderHelm reviews this pull request label Dec 5, 2026
coderhelm[bot]

This comment was marked as outdated.

…for the org overview

Every duration starts at ready for review, and human review leaves out
the author and every bot. Records keep their state and turn change log,
people's reviews and review requests, and check transitions. A merged or
closed pull request leaves a history row kept 400 days with its run and
session links and revert and follow-up links. A nightly job writes each
org's and repository's snapshot and percentiles, team-scoped and bounded.
…nals

A resumable 14-month backfill reads each organization's closed and merged
pull requests into history under the shared budget, pausing on a held
budget or rate limit and showing its progress per repository. Records
keep separate author, reviewer and bot clocks, drift against the base,
every check attempt (flaky reads as flaky), category and severity; history
adds review coverage, bypass merges, suspect follow-ups with their reason,
and CoderHelm's last run outcome and stop reason.
coderhelm[bot]

This comment was marked as outdated.

@coderhelm
coderhelm Bot dismissed their stale review December 5, 2026 20:04

Superseded by CoderHelm's latest review

coderhelm[bot]

This comment was marked as outdated.

@coderhelm
coderhelm Bot dismissed their stale review December 5, 2026 20:05

Superseded by CoderHelm's latest review

* The org's pull requests in one answer: GET /api/prs/overview

Every pull request in the team's repositories counts, people's, CoderHelm's
and other bots'; CoderHelm's are one slice. Computed facts only, with
thresholds from the scope's own percentiles, no rate on fewer than 10
events, and what isn't stored yet named in `missing`. No per-person
ranking, count or duration; a login appears only as one item's owner.
The summary's numbers are all facts. GET /api/prs takes the overview's
drill-down (stage, past p85/p95). Incident case xz pins it.

* Overview: clippy's shapes, and words without hand-off phrases or loose numbers

The stability line says "over the last month" so every number in the summary
is a fact; the incident case reads the route's source without whitespace, so
formatting can't hide a read.

* A reopened change and a later alert recovery reach their waiting runs at once (#986)

A run stopped because the change it built on closed now goes back to
waiting as soon as GitHub reports the change reopened, not at the
15-minute sweep. The pull request handler sends the team's change check
for a close or a reopen before any return a reopen reaches, naming the
change, and the worker reads the runs that change's close stopped (the
sweep stays the backstop for every team).

A recovery posted after an alert route's quiet window now closes the
run waiting on a person for that alert, through the same path a
recovery posted at once uses (common::run_wake::alert_cleared, which
the gateway's alert_delivery now calls too).

Incident case xx_waits_never_outlive_their_event.
…re, the sync never undoes events, history is never thinned

The repository's approval rule is GitHub's own review decision and the
team's rule is a person's approval; a review no rule requires is named,
never a hold. The sync never reopens a closed record, yields to events
newer than its read, replaces the reviews and requests it lists, and marks
lists cut by their page size. History rows merge by source, so the
backfill never thins a row written from events. The review decision is
worked out at review events and used for bypass only when fresh. Stacks
join within one repository, and the detail decides with the list's own
linked records.
coderhelm[bot]

This comment was marked as outdated.

@coderhelm
coderhelm Bot dismissed their stale review December 5, 2026 22:20

Superseded by CoderHelm's latest review

coderhelm[bot]

This comment was marked as outdated.

coderhelm[bot]

This comment was marked as outdated.

@coderhelm
coderhelm Bot dismissed stale reviews from themself December 5, 2026 22:57

Superseded by CoderHelm's latest review

…st event that wrote it

A page read before an event could undo that event's queue entry, auto-merge
or review decision. Every field both events and the sync write (state,
title, draft, head, base, labels, review requests, reviews, review decision,
checks, mergeability, auto-merge, the merge queue, size) now keeps the time
an event last wrote it, and the sync writes that field only when its read
is newer. Tests cover a queue, an auto-merge and a review decision event
landing after the read and surviving the page.

@coderhelm coderhelm Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved with notes 08dde4d (merged)

let data = match github.graphql_read(pr_record::SEARCH_QUERY, vars).await {
Ok(d) => d,
// A personal account's repositories are searched by user.
Err(_) if as_org && page == 0 => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 FYI: Any error on the first search page switches the owner to a user: search (hardening, not verified)

Err(_) if as_org && page == 0 => { as_org = false; continue; } treats every failure on the first page as 'this is a personal account': a rate limit, a 5xx or a timeout all take it. The rest of this owner's sync, and the removal step, then run on the user: query. If that query returns nothing for an org owner, complete is true with an empty seen. The removal loop then deletes every open record of that owner that no event touched in the last hour. The same pattern is at line 340 for the backfill. I could not check from the repository whether user:<org> returns an org's pull requests. If it doesn't, one transient error costs the owner's records until the next webhooks rebuild them.

This blocks: On the sync/removal main path, a transient error on page 0 flips to a user: query that can yield empty seen and delete the owner's open records, data loss unverified in the PR

FYI, not a block: on the whole picture this is not a named correctness, security or data-loss problem to hold the merge on.

//! What happened to every pull request after it closed, kept long enough to
//! answer "how long do our pull requests usually take" from the org's own
//! history, and the nightly snapshot of each org and repository that the
//! overview reads instead of scanning pull requests on page load.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 FYI: Near-identical helpers added together (scope, not verified)

services/common/src/pr_history.rs adds load next to load_backfill, added in the same change. Keep one helper with the shared logic (a parameter for what differs) and call it from both places. If the ticket truly needs it, say why on a line Wider than the ticket: services/common/src/pr_history.rs: <why>.

FYI, not a block: on the whole picture this is not a named correctness, security or data-loss problem to hold the merge on.

if let Some(r) = &repo {
super::reviewer::validate_repo(r)?;
}
let days =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 FYI: Near-identical helpers added together (scope, not verified)

services/gateway/src/routes/prs_overview.rs adds day next to day_of (in services/common/src/pr_overview.rs), added in the same change. Keep one helper with the shared logic (a parameter for what differs) and call it from both places. If the ticket truly needs it, say why on a line Wider than the ticket: services/gateway/src/routes/prs_overview.rs: <why>.

FYI, not a block: on the whole picture this is not a named correctness, security or data-loss problem to hold the merge on.

@coderhelm
coderhelm Bot dismissed their stale review December 6, 2026 01:33

Superseded by CoderHelm's latest review

@coderhelm

coderhelm Bot commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

Auto-merge
Merged by hand. Nothing left to do.
Commit into main. Merges on its own once every item is done.

@nambok
nambok merged commit e660278 into main Dec 6, 2026
21 checks passed
@nambok
nambok deleted the pull-requests-view branch December 6, 2026 02:03
coderhelm Bot pushed a commit that referenced this pull request Dec 6, 2026
Moves dashboardRef to coderhelm main (e65ef06), which adds the Pull requests
page (#544), the follow-up on main (#545) and the pull requests overview
(#546). The API they read shipped in #985 and #988.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ch-review CoderHelm reviews this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant